import { ModuleNamespace } from 'vite/types/hot'
import { RouteRecordRaw } from 'vue-router'

/**
 * 动态注册路由
 */
const mode = import.meta.env.MODE

let systemRoute: ModuleNamespace | null = null

if (mode === 'development' || mode === 'production') {
  systemRoute = import.meta.glob('@systems/**/routes/*.route.ts', {
    eager: true
  }) as unknown as ModuleNamespace
} else if (mode === 'experimentDesign') {
  systemRoute = import.meta.glob(
    '@systems/experimentDesign/routes/*.route.ts',
    {
      eager: true
    }
  ) as unknown as ModuleNamespace
} else if (mode === 'scenarioDeduce') {
  systemRoute = import.meta.glob('@systems/scenarioDeduce/routes/*.route.ts', {
    eager: true
  }) as unknown as ModuleNamespace
}

const routes: RouteRecordRaw[] = []
if (systemRoute) {
  Object.values(systemRoute).forEach((item) => {
    routes.push(...item.default)
  })
}

export default routes
